<?php

class PhpmailerController extends ApplicationController {
	protected $AppName = "phpmailer";
	protected $IncludeFiles = array("class.phpmailer.php", "phpmailer.config.php");

	private $PHPMailer;
	
	function init(){
		$this->PHPMailer = new PHPMailer();
		
		$ConfigObj = new PHPMailerConfig();
		$Config = $ConfigObj->getConfig();
		
		foreach ($Config as $key => $value){
			$this->PHPMailer->$key = $value;
		}
		
		return $this;
	}
	
	function getMailer(){
		return $this->PHPMailer;
	}
	
	function sendMail($address, $body, $subject, $altbody = null, $headers = null){
		if(!isset($this->PHPMailer)){
			$this->init();
		}
		
		$this->PHPMailer->Subject = $subject;
		$this->PHPMailer->AddAddress($address);
		$this->PHPMailer->Body = $headers.$body;
		$this->PHPMailer->AltBody = ($altbody != null) ? $altbody : "";
		
		if(!$this->PHPMailer->Send()){
			return false;
		}
		
		$this->PHPMailer->ClearAddresses();
		
		return true;
	}
	
	function getError(){
		return $this->PHPMailer->ErrorInfo;
	}
	
}

?>